package
{
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;
    import flash.text.*;

    import model.*;

    public class Game extends Sprite
    {
        private var cellMap:CellMap;
        private var traceOut:TextField;
        private var last:Number;

        public function Game()
        {
            x = 0;
            y = 0;
            cellMap = new CellMap();
            addChild(cellMap);

            traceOut = new TextField();
            traceOut.text = "what";
            traceOut.textColor = 0xffff00;
            traceOut.x = 0;
            traceOut.y = 0;
            traceOut.height = 20;
            addChild(traceOut);

            var timer:Timer = new Timer(30, 0);
            last = getTimer();
            timer.start();
            timer.addEventListener(TimerEvent.TIMER, timerListener);
        }

        public function timerListener(e:TimerEvent):void
        {
            var now:Number = getTimer();
            traceOut.text = "FPS: " + (int(1000/(now - last))).toString();
            last = now;
            cellMap.display();
            this.drawBackground();
            e.updateAfterEvent();
        }

        public function drawBackground():void
        {
            graphics.clear();
            graphics.beginFill(0x000000, 1);
            graphics.drawRect(0, 0, 640, 480);
            graphics.endFill();
        }
    }
}
